#ifndef MESSAGE_H
#define MESSAGE_H

class QUINCE_CORE_EXPORT Message
{
public:
    explicit Message(const string &code = string());

    string code() const { return m_code; }
    void setCode(const string &c) { m_code = c; }

    template <typename T>
    void addContent(const string &name, const T &value)
    {
        QVariant obj;
        obj.setValue(value);
        m_content[name] = obj;
    }


    template <typename T>
    T getContent(const string &name, const T &defaultValue) const {
        ContentMap::const_iterator it = m_content.find(name);
        if (it != m_content.end()) {
            return it->second.value<T>();
        }
        return defaultValue;
    }

    template <typename T>
    void getContent(const string &name, const T &defaultValue, T &value) const {
        ContentMap::const_iterator it = m_content.find(name);
        value = it != m_content.end() ? it->second.value<T>() : defaultValue;
    }

    string toReadableString() const;

private:
    string m_code;
    typedef map<string, QVariant> ContentMap;
    ContentMap m_content;
};

#endif // MESSAGE_H
